<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>第三方紧急联系人</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<form id="formSet1">
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_100">
					<div class="sqPanel">
		                <div class="sqPanel_head inL">
		                    <div class="btnsBox inLC">
		                        <span id="addBtn" class="sq-button sq-button-round" onclick="addLinkManRow();">添加</span>
		                        <span id="addLinkManBtn" class="sq-button sq-button-round" onclick="addLinkMan();" class="sq-button sq-button-round">保存</span>
		                        <span id="delBtn" class="sq-button sq-button-round" onclick="delLinkMan();">删除</span>
		                    </div>
		                    <span>第三方紧急联系人</span>
		                </div>
		                <div class="sqPanel_body">
		                    <div id="prjLinkManGrid" class="sq-grid"></div>
		                </div>
					</div>
				</div>
			</div>
			<%-- <div class="btnsBox">
                <input type="hidden" id="visitId" name="visitId" value="${visitId }">
            </div> 
            <div class="btnsBox">
                <input type="hidden" id="visitId" name="visitId" value="${visitId }">
            </div>  --%>
		</form>
	</div>
</div>

<script type="text/javascript">
var prjId = "${prjId}";
var detailFlag = "${detailFlag}";
var genderCdList = [];
<c:if test="${not empty genderCdList}"> genderCdList = ${genderCdList}; </c:if>
var rlCdArr =[];
rlCdArr = ${rlCdList};
$(function(){
	$('#formSet1').ligerForm({
        validate : true,
      
	});
	if(detailFlag == "true"){
		LookAddEmergencyContact();
		$("#addBtn").hide();
		$("#addLinkManBtn").hide();
		$("#delBtn").hide();
	}else{
		 addtoAddEmergencyContact();
	}
	 
	  
})
  //紧急联系人初始化列表
	function addtoAddEmergencyContact(){
		var params = {};
		params = {prjId:prjId}
		$("#prjLinkManGrid").ligerGrid({
			url: '<%=path%>/project/prjlinkman/initList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	             { display: '联系人姓名', name: 'lnkNm', minWidth: 140 ,editor: {type: 'text'},
	  	            	enabledSort:true},
	            { display: '联系电话', name: 'mp', minWidth: 100 ,editor: {type: 'text'},enabledSort:true},
	            { display: '性别', name: 'genderCdNm', minWidth: 140 ,
	         	    editor: {
                       type: 'select',
                       data: genderCdList,
                       valueField: 'key',
                       textField: 'value'
                   },
                   valueField: 'genderCd',
                   textField: 'genderCdNm',
                   render: function (item) {
                       return item.genderCdNm;
                   },
	            	enabledSort:true},
	            { display: '与承租人关系',
	            	    editor: {
	                       type: 'select',
	                       data: rlCdArr,
	                       valueField: 'key',
	                       textField: 'value'
	                   }, 
	                   valueField: 'rlCd',
	                   textField: 'rlCdNm',
	                   render: function (item) {
	                       return item.rlCdNm;
	                   },
	            	name: 'rlCdNm', minWidth: 140},
	            { display: '访谈记录', name: 'visRec',editor: {type: 'text'}, minWidth: 500}
	            
	        ],
	        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
                if (e.selected && e.column.columnname == "rlCdNm") {
                    e.record.rlCdId = e.value;
                    e.value = e.selected[e.column.editor.textField];
                    e.record.rlCd = e.record.rlCdId;
                }
                if (e.selected && e.column.columnname == "genderCdNm") {
                    e.record.genderCdId = e.value;
                    e.value = e.selected[e.column.editor.textField];
                    e.record.genderCd = e.record.genderCdId;
                }
            },
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        heightDiff:-2,
	        checkbox:true,
	        enabledEdit: true,
	        allowUnSelectRow: true,
            alternatingRow: false,
	        rownumbers:true,
	        usePagerOnLessPagesize: false,
	    });
		urgentPrjLinkManGrid = liger.get("prjLinkManGrid");
	}
//紧急联系人初始化列表
function LookAddEmergencyContact(){
	var params = {};
	params = {prjId:prjId}
	$("#prjLinkManGrid").ligerGrid({
		url: '<%=path%>/project/prjlinkman/initList.do',
    	method : 'get',
    	parms:params,
        columns: [
             { display: '联系人姓名', name: 'lnkNm', minWidth: 140 ,
  	            	enabledSort:true},
            { display: '联系电话', name: 'mp', minWidth: 100 ,enabledSort:true},
            { display: '性别', name: 'genderCdNm', minWidth: 140 ,
               valueField: 'genderCd',
               textField: 'genderCdNm',
               render: function (item) {
                   return item.genderCdNm;
               },
            	enabledSort:true},
            { display: '与承租人关系',
                   valueField: 'rlCd',
                   textField: 'rlCdNm',
                   render: function (item) {
                       return item.rlCdNm;
                   },
            	name: 'rlCdNm', minWidth: 140},
            { display: '访谈记录', name: 'visRec', minWidth: 500}
            
        ],
        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
            if (e.selected && e.column.columnname == "rlCdNm") {
                e.record.rlCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
                e.record.rlCd = e.record.rlCdId;
            }
            if (e.selected && e.column.columnname == "genderCdNm") {
                e.record.genderCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
                e.record.genderCd = e.record.genderCdId;
            }
        },
        pageSize:10,
        root:'rows',
        record:'total',
        hideLoadButton : true,
        width: '100%',
        heightDiff:-2,
        checkbox:true,
        enabledEdit: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        rownumbers:true,
        usePagerOnLessPagesize: false,
    });
	urgentPrjLinkManGrid = liger.get("prjLinkManGrid");
}

	//保存紧急联系人信息
	function addLinkMan(){
		  var prjlinkManList = urgentPrjLinkManGrid.getData();
		var params = {};
		params.prjId = prjId;
		params.prjlinkManList = JSON.stringify(prjlinkManList);
	     var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:params,
				url: '<%=path%>/project/prjlinkman/add.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					 wait_dialog.close();
					 if(msg.success == 1){
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
						 urgentPrjLinkManGrid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
	}
//添加
function addLinkManRow(){
	//添加担保人信息
 	var manager = $("#prjLinkManGrid").ligerGetGridManager();
      manager.addRow({
      lnkNm:'',
	mp:'',
	genderCd:'',
	genderCdNm:'',
	rlCd:'',
	rlCdNm:'',
	visRec:'',
     });
}
//删除紧急联系人
$("#delBtn").click(function (event) {
	var linManIds =[] ;
	var  manager  = $("#prjLinkManGrid").ligerGetGridManager();
	var data = manager.getSelecteds();//获取选中行
	 if (data.length ==0) { alert('请选择行'); return; }
	 var parms=JSON.stringify(data);
	 $.ajax({
		 type: 'post',
			dataType:'json',
			data:{parms:parms},
			url:'<%=path%>/project/prjlinkman/delByLinkMans.do',
		 	beforeSend: function(){
		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     }, 
		     success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					 $.ligerDialog.SQalert({content:"删除成功！", SQ_type: "success"});
					 urgentPrjLinkManGrid.reload();
					 
				 }else if(msg.data == null){
					 manager.deleteSelectedRow();
				     $.ligerDialog.SQalert({content:"删除成功！", SQ_type: "success"});
				 }else{
					 $.ligerDialog.SQalert({content:"删除失败！", SQ_type: "error"});
				 }
			}
	 })
})

</script>

</body>
</html>
